package org.openstack.service.sample;

import org.openstack.api.sample.SampleService;
import org.openstack4j.api.telemetry.MeterService;
import org.openstack4j.model.telemetry.MeterSample;
import org.openstack4j.model.telemetry.Sample;
import org.openstack4j.model.telemetry.SampleCriteria;
import org.openstack4j.openstack.telemetry.internal.MeterServiceImpl;

import java.util.List;

/**
 * Created by jiyun on 2017/8/28.
 */
public class SampleServiceImpl implements SampleService {

    private org.openstack4j.api.telemetry.SampleService service
            = new org.openstack4j.openstack.telemetry.internal.SampleServiceImpl();
    private MeterService meterService = new MeterServiceImpl();

    /**
     * 获取所有监控指标的测量值
     *
     * @return 监控数据列表
     */
    @Override
    public List<? extends Sample> getSampleList() {
        return service.list();
    }

    /**
     * 通过Sample ID获取Sample实例
     *
     * @param sampleId 监控数据ID
     * @return Sample 实例
     */
    @Override
    public Sample getSampleById(String sampleId) {
        return service.get(sampleId);
    }

    /**
     * 通过查询条件查询
     * 如：按时间区间、资源ID、ProjectId等。
     *
     * @param criteria 查询条件
     * @return 监控值实例
     */
    @Override
    public List<? extends Sample> querySamples(SampleCriteria criteria) {
        return service.list(criteria);
    }

    /**
     * 指定监控指标的条件查询
     *
     * @param meterName 监控指标名称
     * @param criteria  查询条件
     * @return 监控值实例
     */
    @Override
    public List<? extends MeterSample> querySamples(String meterName, SampleCriteria criteria) {
        return meterService.samples(meterName, criteria);
    }


}
